package com.wish.basic.utils;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class McroUtils {

    public static void main(String[] args) {
        testCreateCode();
    }

    public static  void testCreateCode(){

        FastAutoGenerator.create("jdbc:mysql://192.168.71.130:3306/wish5-system?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=Asia/Shanghai",
                        "root",
                        "root")
                .globalConfig(builder -> {
                    builder.author("lyk") // 设置作者
                            //    .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .commentDate("yyyy-MM-dd")
                            .outputDir("E:/mcode"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.wish.entity") //  toupdate 设置父包名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "E:/mcode/mapper")); // 设置mapperXml生成路径
                }).strategyConfig(builder -> {
                    builder.controllerBuilder().enableRestStyle();// 设置成restful风格 controller 上是否添加REestController
                })
                .strategyConfig(builder -> {
                    builder.mapperBuilder().enableBaseColumnList().enableBaseResultMap();
                })
                .strategyConfig(builder -> {
                    builder.addInclude("t_menu","t_role","t_user","t_role_menu","t_user_role","t_user_menu") // 设置需要生成的表名
                            .addTablePrefix("t_"); // 设置过滤表前缀
                }).strategyConfig(builder -> {
                    builder.entityBuilder()
                            .enableLombok()
                            .columnNaming(NamingStrategy.underline_to_camel)
                            .logicDeleteColumnName("del_flag")  // 逻辑删除
                            .idType(IdType.AUTO). // 是否需要自增主键
                            build();
                    ;
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();

    }

}
